<template>
  <el-drawer
    v-model="showDrawer"
    :title="title"
    :size="size"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    :destroy-on-close="destroyOnClose"
  >
    <div class="formDrawer">
      <div class="body">
        <slot></slot>
      </div>
      <div class="actions" v-if="showButton">
        <el-button
          round
          class="bg-indigo-500 text-light-200"
          @click="submit"
          :loading="loading"
          >{{ confirmText }}</el-button
        >
        <el-button
          round
          class="bg-indigo-500 text-light-200"
          type="default"
          @click="close"
          >取 消</el-button
        >
      </div>
    </div>
  </el-drawer>
</template>

<script setup>
import { ref } from "vue";


const props = defineProps({
  title: String,
  size: {
    type: String,
    default: "45%",
  },
  destroyOnClose: {
    type: Boolean,
    default: false,
  },
  confirmText: {
    type: String,
    default: "提 交",
  },
  showButton: {
    type: Boolean,
    default: true,
  }
});

const emit = defineEmits(["submit"]);
const submit = () => emit("submit");

const loading = ref(false);
// 打开关闭按钮加载状态
const showLoading = () => (loading.value = true);
const hideLoading = () => (loading.value = false);

const showDrawer = ref(false);
// 打开消息抽弹框
const open = () => (showDrawer.value = true);

// 关闭消息抽弹框
const close = () => (showDrawer.value = false);

// 向父组件暴露组件方法
defineExpose({
  open,
  close,
  showLoading,
  hideLoading,
});
</script>

<style>
.formDrawer {
  width: 100%;
  height: 100%;
  @apply flex flex-col;
  position: relative;
}
.formDrawer .body {
  flex: 1;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 50px;
  overflow-y: auto;
}
.formDrawer .actions {
  height: 50px;
  @apply mt-auto flex items-center;
}
</style>